package org.ezplatform.office.meeting.info.service;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
import org.ezplatform.util.GlobalConstant;
import org.ezplatform.util.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.csb.sdk.HttpCaller;
import com.alibaba.csb.sdk.HttpCallerException;
import com.alibaba.fastjson.JSON;

/**
 * 京东方会议系统调用服务
 * 
 * @author zhaozy
 */
@Service("JdfMeetingService")
public class JdfMeetingService {
	public static long testTokenCount=0;
	public static long testMonthCount=0;
	public static long testDayCount=0;

	@Value("${app.boe.meetingsys.web.url:}")
	private String jdfMeetingsysUrl;

	@Value("${app.boe.apigateway.web.url:}")
	private String jdfApiGatewayUrl;

	@Value("${app.boe.web.ak:}")
	private String boeAk;

	@Value("${app.boe.web.sk:}")
	private String boeSk;

	private final static Logger logger = LoggerFactory.getLogger(JdfMeetingService.class);

	/**
	 * 获取京东方与当前用户相关的会议信息
	 * 
	 * @param startTime
	 * @param endTime
	 * @param title     会议标题
	 * @param userId
	 * @param userCode  用户工号
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getJdfMeetingListByParam(String startTime, String endTime, String title,
			String userId, String userCode) {
		logger.debug(
				"zhaozy:getJdfMeetingListByParam:" + " jdfMeetingsysUrl:" + jdfMeetingsysUrl + " startTime:" + startTime
						+ " endTime:" + endTime + " title:" + title + " userId:" + userId + " userCode:" + userCode);
		if (StringUtils.isBlank(jdfMeetingsysUrl)) {
			return Collections.emptyList();
		}
		Pattern patternDate = Pattern.compile("^(\\d+)-(\\d+)");
		List<String> between = getStartAndEndBetweenDate(startTime, endTime);
//		logger.error(" meetingCallApiCount:startTime:"+startTime+
//				" meetingCallApiCount:endTime:"+endTime+
//				" meetingCallApiCount:monthSize:"+between.size()+
//				" meetingCallApiCount:testMonthCount:"+JdfMeetingService.testMonthCount+
//				" meetingCallApiCount:title:"+title+
//				" meetingCallApiCount:userId:"+userId+
//				" meetingCallApiCount:userCode:"+userCode);
		String token = getJdfMeetingSysToken(userCode);
		List<Map<String, Object>> returnData = new ArrayList<>();
		for (String yearMonth : between) {
			Matcher matcherDate = patternDate.matcher(yearMonth);
			boolean dateVal = matcherDate.find();
			if (dateVal) {
				String year = matcherDate.group(1);
				String month = matcherDate.group(2);
				testMonthCount++;
				List<Map<String, Object>> meetingSchedule = getMeetingSchedule(year, month, token);
				Map<String, String> jdfTypeMap = null;
				for (Map<String, Object> dateSchedule : meetingSchedule) {
					String day=(String) dateSchedule.get("day");
					//检查day是否在开始日期和结束日期之间，是的话返回
					if(!isPass(startTime,endTime,day)) {
						continue;
					}
					List<Map<String, Object>> meetingInfoVos = (List<Map<String, Object>>) dateSchedule
							.get("meetingInfoVos");
					Map<String, Object> ele = null;
					for (Map<String, Object> tempEle : meetingInfoVos) {
						String mstartDate =parseDate((String) tempEle.get("mstartDate"));
						ele = new HashMap<String, Object>();
						ele.put("name", parseNullString(tempEle.get("msite")));
						ele.put("id", parseNullString(tempEle.get("id")));
						ele.put("createdUserId", parseNullString(tempEle.get("createUserId")));
						ele.put("createUserName", parseNullString(tempEle.get("createUserName")));
						ele.put("status", parseNullString(tempEle.get("status")));
						ele.put("createdDate", parseNullString(tempEle.get("createTime")));
						ele.put("startTime", parseDate((String) tempEle.get("mstartDate")));
						ele.put("endTime", parseDate((String) tempEle.get("mendDate")));
						ele.put("meetingCode", parseNullString(tempEle.get("meetingCode")));
						String jdfType = "", enterUrl = "";
						if (tempEle.get("type") == null || String.valueOf(tempEle.get("type")).equals("2")) {
							String typeUrl=jdfMeetingsysUrl + "/meeting/meeting?size=10&msite=";
							try {
								String msite=URLEncoder.encode((String)parseNullString(tempEle.get("msite")),"utf-8");
								typeUrl += msite + "&date=" + dateSchedule.get("day");
							} catch (UnsupportedEncodingException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
								logger.error("url编码异常："+typeUrl, e);
							}
							testDayCount++;
							jdfTypeMap = getMeetingType(typeUrl, (String) parseNullString(tempEle.get("meetingCode")),
									token);
							jdfType = jdfTypeMap.get("type");
							enterUrl = jdfTypeMap.get("enterUrl");
						}
						ele.put("jdfType", jdfType);
						ele.put("enterUrl", enterUrl);
						
						logger.debug(
								"zhaozy:msite:" + tempEle.get("msite") + " meetingCode:" + tempEle.get("meetingCode"));
						returnData.add(ele);
					}
				}
			}
		}
		return returnData;
	}
	
	/**
	 * 获取京东方与当前用户相关的会议信息<br/>
	 * 前一个getJdfMeetingListByParam方法由于京东方会议系统的接口问题现改用这个方法获取
	 * @param startTime
	 * @param endTime
	 * @param title     会议标题
	 * @param userId
	 * @param userCode  用户工号
	 * @return
	 */
	public List<Map<String, Object>> getJdfMeetingListByParam2(String startTime, String endTime, String title,
			String userId, String userCode) {
		logger.debug(
				"zhaozy:getJdfMeetingListByParam2:" + " jdfMeetingsysUrl:" + jdfMeetingsysUrl + " startTime:" + startTime
						+ " endTime:" + endTime + " title:" + title + " userId:" + userId + " userCode:" + userCode);
		if (StringUtils.isBlank(jdfMeetingsysUrl)) {
			return Collections.emptyList();
		}
		List<String> between = getStartAndEndBetweenDateDay(startTime, endTime);
		String token = getJdfMeetingSysToken(userCode);
		List<Map<String, Object>> returnData = new ArrayList<>();
		List<Map<String, Object>>  mineMeetings=null;
		Map<String, Object> ele = null;
		for (String yearMonthDay : between) {
			mineMeetings=getMineMeeting(yearMonthDay,1000,token);
			for (Map<String, Object> tempEle : mineMeetings) {
				ele = new HashMap<String, Object>();
				ele.put("name", parseNullString(tempEle.get("msite")));
				ele.put("id", parseNullString(tempEle.get("id")));
				ele.put("createdUserId", parseNullString(tempEle.get("createUserId")));
				ele.put("createUserName", parseNullString(tempEle.get("createUserName")));
				ele.put("status", parseNullString(tempEle.get("status")));
				ele.put("createdDate", parseNullString(tempEle.get("createTime")));
				ele.put("startTime", parseDate((String) tempEle.get("mstartDate")));
				ele.put("endTime", parseDate((String) tempEle.get("mendDate")));
				ele.put("meetingCode", parseNullString(tempEle.get("meetingCode")));
				ele.put("jdfType", parseNullString(tempEle.get("type")));
				ele.put("enterUrl", parseNullString(tempEle.get("enterUrl")));
				returnData.add(ele);
			}
		}
		return returnData;
	}
	
	 /**
	  * 获取我创建的/参加的会议
	 * @param date
	 * @param size
	 * @param token
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getMineMeeting(String date,int size,String token){
		String url=jdfMeetingsysUrl + "/meeting/meeting?size="+size+"&date="+date;
		logger.debug("zhaozy:getMineMeeting:url:" + url + " token:" + token);
		String meeting = JdfMeetingService.httpGet(url, token);
		logger.info("zhaozy:mineMeeting " + meeting);
		Map<String, Object> meetingMap = JsonUtils.readValue(meeting);
		Map<String, Object> returnMapData = new HashMap<>();
		List<Map<String, Object>> returnData = new ArrayList<>();
		if ("0".equals(String.valueOf(meetingMap.get("code")))) {
			returnMapData = (Map<String, Object>) meetingMap.get("data");
			if (returnMapData != null && returnMapData.size() > 0) {
				returnData = (List<Map<String, Object>>) returnMapData.get("list");
			}
		}
		return returnData;
	 }

	/**
	 * 获取京东方会议系统当前用户日程列表
	 * 
	 * @param month
	 * @param year
	 * @param token
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getMeetingSchedule(String year, String month, String token) {
		logger.debug("zhaozy:getMeetingSchedule:year:" + year + " month:" + month + " token:" + token);
		String url = jdfMeetingsysUrl + "/meeting/meeting/schedule?month=" + month + "&year=" + year;
		String meetingSchedule = JdfMeetingService.httpGet(url, token);
		logger.info("zhaozy:schedule " + meetingSchedule);
		Map<String, Object> schedule = JsonUtils.readValue(meetingSchedule);
		List<Map<String, Object>> returnData = new ArrayList<>();
		if ("0".equals(String.valueOf(schedule.get("code")))) {
			returnData = (List<Map<String, Object>>) schedule.get("data");
		}
		return returnData;
	}

	/**
	 * 获取京东方会议详情
	 * 
	 * @param meetingCode
	 * @param userCode    用户工号
	 * @param type
	 * @return
	 */
	public Map<String, Object> getMeetingDetailByMeetingCode(String meetingCode, String userCode, int type) {
		logger.debug("zhaozy:getMeetingDetailByMeetingCode:userCode:" + userCode + " meetingCode:" + meetingCode
				+ " type:" + type);
		String token = getJdfMeetingSysToken(userCode);
		logger.debug("zhaozy:getMeetingDetailByMeetingCode:token:" + token);
		switch (type) {
		case 1:
			return getGeneralMeeting(meetingCode, token);
		case 2:
			return getMixtureMeeting(meetingCode, token);
		case 3:
			return getVideoMeeting(meetingCode, token);
		case 4:
			return getTelMeeting(meetingCode, token);
		}
		return new HashMap<String, Object>(1);
	}

	/**
	 * 融合会议
	 * 
	 * @param meetingCode
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Object> getMixtureMeeting(String meetingCode, String token) {
		logger.debug("zhaozy:getMixtureMeeting:start");
		String resultJson = JdfMeetingService.httpGet(jdfMeetingsysUrl + "/meeting/mixtureMeeting/" + meetingCode,
				token);
		logger.debug("zhaozy:resultJson: " + resultJson);
		Map<String, Object> returnData = new HashMap<>();
		Map<String, Object> returnEntity = new HashMap<>();
		if (resultJson == null) {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		Map<String, Object> meeting = JsonUtils.readValue(resultJson);
		if ("0".equals((String.valueOf(meeting.get("code"))))) {
			Map<String, Object> info = (Map<String, Object>) meeting.get("data");
			if (info != null) {
				returnData.put("boardroomName", parseNullString(info.get("addressName")));
				returnData.put("attachment", "");
				if (info.get("parMeetingAttendees") != null) {
					StringBuffer sbAttendees = new StringBuffer();
					List<Map<String, Object>> list = (List<Map<String, Object>>) info.get("parMeetingAttendees");
					for (Map<String, Object> attendee : list) {
						sbAttendees.append(attendee.get("username") + ",");
					}
					if (sbAttendees.length() > 0) {
						returnData.put("attendUserName", sbAttendees.substring(0, sbAttendees.length() - 1));
					}
				}
				returnData.put("address", parseNullString(info.get("location")));
				returnData.put("meetingType", "融合会议");
				returnEntity.put("address", parseNullString(info.get("location")));
				returnEntity.put("name", parseNullString(info.get("msite")));
				returnEntity.put("content", parseNullString(info.get("mcontent")));
				returnEntity.put("startTime", parseDate((String) info.get("mstartDate")));
				returnEntity.put("endTime", parseDate((String) info.get("mendDate")));
				returnEntity.put("isCycle", 0);
				returnEntity.put("cycleType", 0);
				returnEntity.put("isNotice", 0);
				returnEntity.put("isSigned", 0);
				returnEntity.put("isSync", 1);
				returnEntity.put("remark", "");
				returnData.put("entity", returnEntity);
			}

		} else {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		return returnData;
	}

	/**
	 * 一般会议
	 * 
	 * @param meetingCode
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Object> getGeneralMeeting(String meetingCode, String token) {
		logger.debug("zhaozy:getGeneralMeeting:start");
		String resultJson = JdfMeetingService.httpGet(jdfMeetingsysUrl + "/meeting/meeting/" + meetingCode, token);
		logger.debug("zhaozy:resultJson: " + resultJson);
		Map<String, Object> returnData = new HashMap<>();
		Map<String, Object> returnEntity = new HashMap<>();
		if (resultJson == null) {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		Map<String, Object> meeting = JsonUtils.readValue(resultJson);
		if ("0".equals((String.valueOf(meeting.get("code"))))) {
			Map<String, Object> info = (Map<String, Object>) meeting.get("data");
			if (info != null) {
				returnData.put("boardroomName", parseNullString(info.get("addressName")));
				returnData.put("attachment", "");
				if (info.get("innerAttendees") != null) {
					StringBuffer sbAttendees = new StringBuffer();
					List<Map<String, Object>> list = (List<Map<String, Object>>) info.get("innerAttendees");
					for (Map<String, Object> attendee : list) {
						sbAttendees.append(attendee.get("username") + ",");
					}
					if (sbAttendees.length() > 0) {
						returnData.put("attendUserName", sbAttendees.substring(0, sbAttendees.length() - 1));
					}
				}
				returnData.put("address", parseNullString(info.get("location")));
				returnData.put("meetingType", "一般会议");
				returnEntity.put("address", parseNullString(info.get("location")));
				returnEntity.put("name", parseNullString(info.get("msite")));
				returnEntity.put("content", parseNullString(info.get("mcontent")));
				returnEntity.put("startTime", parseDate((String) info.get("mstartDate")));
				returnEntity.put("endTime", parseDate((String) info.get("mendDate")));
				returnEntity.put("isCycle", 0);
				returnEntity.put("cycleType", 0);
				returnEntity.put("isNotice", 0);
				returnEntity.put("isSigned", 0);
				returnEntity.put("isSync", 1);
				returnEntity.put("remark", "");
				returnData.put("entity", returnEntity);
			}

		} else {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		return returnData;
	}

	/**
	 * 电话会议
	 * 
	 * @param meetingCode
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Object> getTelMeeting(String meetingCode, String token) {
		logger.debug("zhaozy:getTelMeeting: start");
		String resultJson = JdfMeetingService
				.httpGet(jdfMeetingsysUrl + "/meeting/telMeeting?meetingCode=" + meetingCode, token);
		logger.debug("zhaozy:getTelMeeting: " + resultJson);
		Map<String, Object> returnData = new HashMap<>();
		Map<String, Object> returnEntity = new HashMap<>();
		if (resultJson == null) {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		Map<String, Object> meeting = JsonUtils.readValue(resultJson);
		if ("0".equals((String.valueOf(meeting.get("code"))))) {
			Map<String, Object> info = (Map<String, Object>) meeting.get("data");
			if (info != null) {
				Map<String, Object> meetingInfo = (Map<String, Object>) info.get("meetingInfo");
				returnData.put("boardroomName", parseNullString(info.get("addressName")));
				returnData.put("attachment", "");
				if (info.get("attendees") != null) {
					StringBuffer sbAttendees = new StringBuffer();
					List<Map<String, Object>> list = (List<Map<String, Object>>) info.get("attendees");
					for (Map<String, Object> attendee : list) {
						sbAttendees.append(attendee.get("username") + ",");
					}
					if (sbAttendees.length() > 0) {
						returnData.put("attendUserName", sbAttendees.substring(0, sbAttendees.length() - 1));
					}
				}
				returnData.put("meetingType", "电话会议");
				returnEntity.put("address", parseNullString(info.get("location")));
				returnEntity.put("name", parseNullString(meetingInfo.get("msite")));
				returnEntity.put("content", parseNullString(meetingInfo.get("mcontent")));
				returnEntity.put("startTime", parseDate((String) meetingInfo.get("mstartDate")));
				returnEntity.put("endTime", parseDate((String) meetingInfo.get("mendDate")));
				returnEntity.put("isCycle", 0);
				returnEntity.put("cycleType", 0);
				returnEntity.put("isNotice", 0);
				returnEntity.put("isSigned", 0);
				returnEntity.put("isSync", 1);
				returnEntity.put("remark", parseNullString(info.get("mdescripition")));
				returnData.put("entity", returnEntity);
			}

		} else {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		return returnData;
	}

	/**
	 * 视频会议
	 * 
	 * @param meetingCode
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Object> getVideoMeeting(String meetingCode, String token) {
		logger.debug("zhaozy:getTelMeeting:start");
		String resultJson = null;
		try {
			resultJson = JdfMeetingService
					.httpGet(jdfMeetingsysUrl + "/meeting/videoMeeting?&meetingCode=" + meetingCode, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
		logger.debug("zhaozy:getTelMeeting: " + resultJson);
		Map<String, Object> returnData = new HashMap<>();
		Map<String, Object> returnEntity = new HashMap<>();
		if (resultJson == null) {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		Map<String, Object> meeting = JsonUtils.readValue(resultJson);
		if ("0".equals(String.valueOf(meeting.get("code")))) {
			Map<String, Object> info = (Map<String, Object>) meeting.get("data");
			if (info != null) {
				Map<String, Object> infoReally = (Map<String, Object>) info.get("meetingInfo");
				returnData.put("boardroomName", parseNullString(info.get("addressName")));
				returnData.put("attachment", "");
				if (info.get("participants") != null) {
					StringBuffer sbAttendees = new StringBuffer();
					List<Map<String, Object>> list = (List<Map<String, Object>>) info.get("participants");
					for (Map<String, Object> attendee : list) {
						sbAttendees.append(attendee.get("username") + ",");
					}
					if (sbAttendees.length() > 0) {
						returnData.put("attendUserName", sbAttendees.substring(0, sbAttendees.length() - 1));
					}
				}
				returnData.put("address", parseNullString(info.get("location")));
				returnData.put("meetingType", "视频会议");
				returnEntity.put("address", parseNullString(info.get("location")));
				returnEntity.put("name", parseNullString(infoReally.get("msite")));
				returnEntity.put("content", parseNullString(infoReally.get("mcontent")));
				returnEntity.put("startTime", parseDate((String) infoReally.get("mstartDate")));
				returnEntity.put("endTime", parseDate((String) infoReally.get("mendDate")));
				returnEntity.put("isCycle", 0);
				returnEntity.put("cycleType", 0);
				returnEntity.put("isNotice", 0);
				returnEntity.put("isSigned", 0);
				returnEntity.put("isSync", 1);
				returnEntity.put("remark", "");
				returnData.put("entity", returnEntity);
			}

		} else {
			returnData.put("entity", returnEntity);
			return returnData;
		}
		return returnData;
	}

	/**
	 * 获取免登token
	 * 
	 * @return
	 */
	public String getJdfMeetingSysToken(String userCode) {
		return getToken(jdfApiGatewayUrl, "get", userCode, "1.0.0");
	}

	public static String httpGet(String url, String token) {
		HttpGet httpGet = new HttpGet(url);
		CloseableHttpResponse response = null;
		CloseableHttpClient httpClient = HttpClients.createDefault();
		RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
		httpGet.setConfig(requestConfig);
		httpGet.addHeader("Referer", GlobalConstant.getAppFlexOfficeServerUrl());
		httpGet.addHeader("x-auth-token", token);

		try {
			response = httpClient.execute(httpGet, new BasicHttpContext());

			if (response.getStatusLine().getStatusCode() != 200) {
				return null;
			}
			HttpEntity entity = response.getEntity();
			if (entity != null) {
				String resultStr = EntityUtils.toString(entity, "utf-8");
				return resultStr;
			}
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("获取会议系统数据失败", e);
		} finally {
			if (response != null)
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

		return null;
	}

	public static String httpPost(String url, String token, Object data) throws Exception {
		HttpPost httpPost = new HttpPost(url);
		CloseableHttpResponse response = null;
		CloseableHttpClient httpClient = HttpClients.createDefault();
		RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
		httpPost.setConfig(requestConfig);
		httpPost.addHeader("Content-Type", "application/json");
		httpPost.addHeader("Referer", GlobalConstant.getAppFlexOfficeServerUrl());
		httpPost.addHeader("x-auth-token", token);
		try {
			StringEntity requestEntity = new StringEntity(JSON.toJSONString(data), "utf-8");
			httpPost.setEntity(requestEntity);

			response = httpClient.execute(httpPost, new BasicHttpContext());

			if (response.getStatusLine().getStatusCode() != 200) {

				return null;
			}
			HttpEntity entity = response.getEntity();
			if (entity != null) {
				String resultStr = EntityUtils.toString(entity, "utf-8");
				return resultStr;
			}
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("获取会议系统数据失败", e);
		} finally {
			if (response != null)
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

		return null;
	}

	/**
	 * 京东方 服务调用获取免登token
	 * 
	 * @param httpUrl   请求接口
	 * @param reqMethod 使用get/post提交请求
	 * @param params    请求参数
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public String getToken(String httpUrl, String reqMethod, String userCode, String version) {
		logger.debug("zhaozy:getToken:httpUrl" + httpUrl + " reqMethod:" + reqMethod + " userCode" + userCode
				+ " version" + version);
		if (httpUrl == null || reqMethod == null || userCode == null) {
			return null;
		}
		reqMethod = reqMethod.toUpperCase();
		Map<String, String> params = new HashMap<String, String>();
		params.put("userCode", userCode);
		String API_NAME = "getTokenByUserCode";
		String ak = boeAk;
		String sk = boeSk;
		String result = null;
		Map<String, Object> resultMap = null;
		httpUrl += "/" + API_NAME;
		try {
			testTokenCount++;
			if ("get".equals(reqMethod.toLowerCase())) {
				result = HttpCaller.doGet(httpUrl, API_NAME, version, params, ak, sk);
				
			} else if ("post".equals(reqMethod.toLowerCase())) {
				result = HttpCaller.doPost(httpUrl, API_NAME, version, params, ak, sk);
			}

			if (result != null) {
				resultMap = JsonUtils.readValue(result);
				logger.debug("zhaozy:resultMap " + resultMap);
				return (String) resultMap.get("data");
			}
		} catch (HttpCallerException e) {
			e.printStackTrace();
			logger.error("获取京东方token失败:", e);
		}
		return result;
	}

	/**
	 * 获取会议类型
	 * 
	 * @param url
	 * @param meetingCode
	 * @param token
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, String> getMeetingType(String url, String meetingCode, String token) {
		logger.debug("zhaozy:getMeetingType:url:" + url + " token:" + token);
		String meeting = JdfMeetingService.httpGet(url, token);
		logger.debug("zhaozy:meeting " + meeting);
		Map<String, Object> meetingMap = JsonUtils.readValue(meeting);
		Map<String, Object> returnMapData = new HashMap<>();
		Map<String, String> returnVal = new HashMap<>(2);
		List<Map<String, Object>> returnData = new ArrayList<>();
		if ("0".equals(String.valueOf(meetingMap.get("code")))) {
			returnMapData = (Map<String, Object>) meetingMap.get("data");
			if (returnMapData != null && returnMapData.size() > 0) {
				returnData = (List<Map<String, Object>>) returnMapData.get("list");
			}
			for (Map<String, Object> ele : returnData) {
				if (meetingCode.equals(ele.get("meetingCode"))) {
					returnVal.put("type", ele.get("type") != null ? String.valueOf(ele.get("type")) : "");
					returnVal.put("enterUrl", ele.get("enterUrl") != null ? String.valueOf(ele.get("enterUrl")) : "");
					return returnVal;
				}
			}
		}
		return returnVal;
	}

	/**
	 * 获取指定时间范围的年月
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	private List<String> getStartAndEndBetweenDate(String startTime, String endTime) {
		Pattern pattern = Pattern.compile("^(\\d+)-(\\d+)-\\d+\\s?");
		Matcher matcherStart = pattern.matcher(startTime);
		Matcher matcherEnd = pattern.matcher(endTime);
		HashSet<String> reSet = new HashSet<String>();
		if (matcherStart.find() && matcherEnd.find()) {
			int yearStart = Integer.valueOf(matcherStart.group(1));
			int monthStart = Integer.valueOf(matcherStart.group(2));
			int yearEnd = Integer.valueOf(matcherEnd.group(1));
			int monthEnd = Integer.valueOf(matcherEnd.group(2));
			Calendar start = Calendar.getInstance();
			start.set(yearStart, monthStart - 1, 1);
			Long startTimeL = start.getTimeInMillis();
			Calendar end = Calendar.getInstance();
			end.set(yearEnd, monthEnd - 1, 1);
			Long endTimeL = end.getTimeInMillis();
			Long oneDay = 1000 * 60 * 60 * 24l;
			Long time = startTimeL;
			DateFormat df = new SimpleDateFormat("yyyy-MM");
			while (time <= endTimeL) {
				Date d = new Date(time);
				reSet.add(df.format(d));
				time += oneDay;
			}
			logger.debug("zhaozy:reSet " + reSet.size());
		}
		return reSet.stream().collect(Collectors.toList());
	}
	
	/**
	 * 获取指定时间范围的年月日
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	private List<String> getStartAndEndBetweenDateDay(String startTime, String endTime) {
		Pattern pattern = Pattern.compile("^(\\d+)-(\\d+)-(\\d+)\\s?");
		Matcher matcherStart = pattern.matcher(startTime);
		Matcher matcherEnd = pattern.matcher(endTime);
		List<String> reList = new ArrayList<String>();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		if (matcherStart.find() && matcherEnd.find()) {
			int yearStart = Integer.valueOf(matcherStart.group(1));
			int monthStart = Integer.valueOf(matcherStart.group(2));
			int dayStart = Integer.valueOf(matcherStart.group(3));
			int yearEnd = Integer.valueOf(matcherEnd.group(1));
			int monthEnd = Integer.valueOf(matcherEnd.group(2));
			int dayEnd = Integer.valueOf(matcherEnd.group(3));
			Calendar start = Calendar.getInstance();
			start.set(yearStart, monthStart - 1, dayStart);
			Long startTimeL = start.getTimeInMillis();
			Calendar end = Calendar.getInstance();
			end.set(yearEnd, monthEnd - 1, dayEnd);
			Long endTimeL = end.getTimeInMillis();
			Long oneDay = 1000 * 60 * 60 * 24l;
			Long time = startTimeL;
			while (time <= endTimeL) {
				Date d = new Date(time);
				reList.add(df.format(d));
				time += oneDay;
			}
			logger.debug("zhaozy:reList " + reList.size());
		}
		return reList;
	}

	/**
	 * 去掉京东方日期后的秒
	 * 
	 * @param boeDate
	 * @return
	 */
	private String parseDate(String boeDate) {
		if (StringUtils.isBlank(boeDate)) {
			return "";
		}
		if (boeDate.length() > 2) {
			return boeDate.substring(0, boeDate.length() - 3);
		}
		return boeDate;
	}

	private Object parseNullString(Object str) {
		return str != null ? str : "";
	}
	
	/**
	 * 检查值在开始日期和结束日期之间
	 * @param startTime
	 * @param endTime
	 * @param validate
	 * @return
	 */
	public boolean isPass(String startTime,String endTime,String validate) {
		Pattern pattern = Pattern.compile("^(\\d+-\\d+-\\d+)\\s?");
		Matcher matcherStart = pattern.matcher(startTime);
		Matcher matcherEnd = pattern.matcher(endTime);
		if(matcherStart.find() && matcherEnd.find()) {
			String start=matcherStart.group(1);
			String end=matcherEnd.group(1);
			if(start.compareTo(validate)<=0 && end.compareTo(validate)>=0) {
				return true;
			}
		}
		return false;
	}
	public static void main(String arg[]) {
		JdfMeetingService jms=new JdfMeetingService();
		System.out.println(jms.getStartAndEndBetweenDate("2019-01-03","2020-03-06 23:13"));
	}
}
